include("cl_inventory_functions.lua")

function Inventory(um)
	local iparent= vgui.Create("DFrame")
	iparent:SetSize(ScrW()*.9,ScrH()*.9)
	iparent:Center()
	iparent:SetVisible(true)
	iparent:SetDraggable(false)
	iparent:SetTitle("Resource RP")
	

	local tabs= vgui.Create("DPropertySheet")
	tabs:SetParent(iparent)
	tabs:SetSize(iparent:GetWide() -20, iparent:GetTall()-50)
	tabs:Center()

	local inventory=vgui.Create("DPanel")
	inventory:SetVisible(true)
	inventory:SetSize(tabs:GetWide(),tabs:GetTall()-30)
	inventory:SetPos(0,10)

	//display inventory code
	local num_lines = um:ReadLong() // Read number of lines.
	local num=1 //layoutvariable
	for i=1, num_lines do
		local key=um:ReadString()
		local value=um:ReadLong()

		if(value>0) then
			// we will use these vars to go across and the down. (parent:getwidth etc)
			local xpos=num*100-90
			local ypos=10
			num=num+1
		
			local SpawnIcon = vgui.Create("SpawnIcon",inventory) -- The Vgui Elemnt is called SpawnIcon
			SpawnIcon:SetModel(ImgVars[key]) --Simply using SetModel for the model
			SpawnIcon:SetPos(xpos, ypos)
			SpawnIcon:SetToolTip(key)

			if(inventorycontextmenu[key.."_primary"]==nil) then
				SpawnIcon.DoClick= function(SpawnIcon,key)	end
			else 
				SpawnIcon.DoClick=function() inventorycontextmenu[key.."_primary"](SpawnIcon,key) end
			end
			if(inventorycontextmenu[key]==nil) then
				SpawnIcon.OpenMenu=function() inventorycontextmenu["default"](SpawnIcon,key) end
			else				
				SpawnIcon.OpenMenu = function() inventorycontextmenu[key](SpawnIcon, key)end
			end

			local myLabel= vgui.Create("DLabel", inventory)
			myLabel:SetText(value)
			myLabel:SetTextColor( Color( 255, 25, 25, 255 ) )
			myLabel:SizeToContents()
			myLabel:SetPos(xpos+SpawnIcon:GetWide()-myLabel:GetWide(),64+ypos)
			
		end	
		
	end 		

	//end display inventory code

	

	local help=vgui.Create("DPanel")
	help:SetSize(300,300)
	help:SetVisible(true)

	local helptext=vgui.Create("DLabel", help)
	helptext:SetText("Helppagecomingsoon")
	helptext:SetTextColor( Color( 255, 25, 25, 255 ) )
	helptext:SetPos(10,30)
	helptext:SizeToContents()

	tabs:AddSheet("Inventory", inventory, "gui/silkicons/user", false, false, "Open Inventory")
	tabs:AddSheet("Help", help, "gui/silkicons/group", false, false, "Show Help")

	iparent:MakePopup()

	iparent.OnKeyCodePressed= function() if(input.IsKeyDown(KEY_F1)) then iparent:Close() end end

end

usermessage.Hook("showInventory", Inventory) 